//
//  AppDelegate.swift
//  微博个人swift
//
//  Created by 李灏 on 16/1/30.
//  Copyright © 2016年 lh. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        setColor()
        registerNotification()
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window?.backgroundColor = UIColor.whiteColor()
        window?.makeKeyAndVisible()
        //设置根控制器
        window?.rootViewController = defaultRootViewController()
//        let compse = PictureSelectorViewController()
//        let nav = BaseNavViewController(rootViewController:compse)
//        window?.rootViewController = nav
        return true
    }
    //注册通知
    private func registerNotification() {
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "choseRootVC:", name: WBSwitchRootVC, object: nil)
    }
    @objc private func choseRootVC(n:NSNotification) {
        if n.object != nil {
            //欢迎页面
            window?.rootViewController = WelcomeViewController()
        }else{
            window?.rootViewController = MainViewController()
        }
    }
    //移除通知
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    //根据用户是否登录指定默认的控制器
    private func defaultRootViewController() ->UIViewController {
        if AccountViewModel.sharedAccountViewModel.userLogin {
            return WelcomeViewController()
        }
        return MainViewController()
    }
    //设置全局颜色 需要提前设置
    private func setColor() {
        UINavigationBar.appearance().tintColor = UIColor.orangeColor()
        UITabBar.appearance().tintColor = UIColor.orangeColor()
    }
}

